package com.base;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

import com.ibatis.po.user.TSubStation;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.lg.system.CSqlMap;

public class CreateXML extends HttpServlet {

	public CreateXML() {
		super();
	}

	public void destroy() {
		super.destroy(); 
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
		doPost(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
		SqlMapClient sqlmap = CSqlMap.getSqlMapConfig();
		List subStationList = null;
		TSubStation subStationPo = new TSubStation();
		response.setContentType("text/xml");
		response.setCharacterEncoding("UTF-8");
		String sortId = request.getParameter("selected");
		PrintWriter out = response.getWriter();

		try{


			//生成岗位列表
			subStationList = sqlmap.queryForList("T_SUB_STATION.selectBySortId",sortId);
			out.println("<res>");
			out.println("<substation>");
			out.println("<stationname>不限</stationname>");
			out.println("<stationvalue>#</stationvalue>");
			out.println("</substation>");
			for(int i=0;i<subStationList.size();i++){
				subStationPo = (TSubStation)subStationList.get(i);
				out.println("<substation>");
				out.println("<stationname>"+subStationPo.getPostName()+"</stationname>");
				out.println("<stationvalue>"+subStationPo.getId()+"</stationvalue>");
				out.println("</substation>");
			}
			out.println("</res>");
			out.flush();
			out.close();
		}catch(Exception e){
			e.printStackTrace();
		}
	}

	public void init() throws ServletException {}

}
